<html>
<head><meta charset="utf-8"><title>lucent use case · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html">lucent use case</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178275363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178275363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178275363">(Oct 16 2019 at 10:13)</a>:</h4>
<p><span class="user-mention" data-user-id="237472">@Adam C. Foltzer</span> can confirm, but from what I understand, the lucent use case is that they have:</p>
<ul>
<li>Rust panics that may unwind native frames</li>
<li>The Rust panic is caught in Rust code </li>
<li>Those native frames have no destructors</li>
<li>This is all on a <code>x86_64-unknown-linux-gnu</code> target triple</li>
</ul>
<p>I think this is a good "first target" to fully define. First question <span class="user-mention" data-user-id="237472">@Adam C. Foltzer</span> is whether I have all the details right.</p>
<p>Next question is whether there are other pertinent details I've omitted.</p>
<p>What would be helpful (I think) would be to get some kind of presentation of what the minimum set of details we would have to specify in order to make that behavior stable and well-defined. I imagine <span class="user-mention" data-user-id="132920">@gnzlbg</span> you have some handle on that.</p>



<a name="178281766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178281766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178281766">(Oct 16 2019 at 12:05)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> IIRC, one detail was that those native frames are actually / often written in Rust, but there are many reasons why lucent cannot use the Rust ABI (too unstable, etc.).</p>



<a name="178281852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178281852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178281852">(Oct 16 2019 at 12:06)</a>:</h4>
<blockquote>
<p>I imagine @gnzlbg you have some handle on that.</p>
</blockquote>
<p>I believe the proposal in my PR solves that problem without any undefined behavior on all Itanium-like targets (most Rust targets, except for windows ones).</p>



<a name="178281993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178281993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178281993">(Oct 16 2019 at 12:08)</a>:</h4>
<p>The proposal does not contain any wording for the windows targets yet though.</p>
<p>Also, if those native frames are indeed written in Rust, then lucent would be a good example for an application that might need the feature proposed in the "Futures section"</p>



<a name="178282013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178282013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178282013">(Oct 16 2019 at 12:08)</a>:</h4>
<p>To avoid paying any "unwind translation" costs if we were to introduce any in the future</p>



<a name="178306324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178306324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178306324">(Oct 16 2019 at 16:40)</a>:</h4>
<p>Hm, avoiding translation costs seems like a future optimization that may or may not be useful enough to pursue - I suspect that a translation layer may just be the cost of cross-platform stability</p>



<a name="178306383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178306383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178306383">(Oct 16 2019 at 16:41)</a>:</h4>
<blockquote>
<p>I believe the proposal in my PR solves that problem without any undefined behavior on all Itanium-like targets (most Rust targets, except for windows ones).</p>
</blockquote>
<p>yeah, it may very well -- that'd be great</p>



<a name="178306434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178306434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178306434">(Oct 16 2019 at 16:42)</a>:</h4>
<p>(actually, let's not even get into that right now, and just leave it at "possibly useful feature described in Futures section")</p>



<a name="178306448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178306448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178306448">(Oct 16 2019 at 16:42)</a>:</h4>
<blockquote>
<p>Also, if those native frames are indeed written in Rust, then lucent would be a good example for an application that might need the feature proposed in the "Futures section"</p>
</blockquote>
<p>maybe so, but no need to worry about that now</p>



<a name="178306466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178306466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178306466">(Oct 16 2019 at 16:42)</a>:</h4>
<blockquote>
<p>Those native frames have no destructors</p>
</blockquote>
<p>I believe last time we spoke to Adam, he said that they definitely do need to handle frames with destructors</p>



<a name="178306481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178306481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178306481">(Oct 16 2019 at 16:42)</a>:</h4>
<p>(Which should not necessarily impact our decision of what an "MVP" looks like)</p>



<a name="178318529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178318529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178318529">(Oct 16 2019 at 18:57)</a>:</h4>
<p>This largely sounds right to me, but I think it's worth digging into what "native frames" mean. We have at least two source languages for frames in Lucet apps: Rust, and Wasm (compiled into x86-64). the runtime system is in Rust, and in practice so is the implementation of the functions Wasm guests import (we call those <em>hostcalls</em>).</p>
<p>When you just run a Wasm guest that does some computation and returns without calling a hostcall, your most complicated call chain looks like <code>Rust -&gt; Wasm</code>.</p>
<p>It gets trickier when you start calling hostcalls, because then you can have <code>Rust -&gt; Wasm -&gt; Rust</code>. It really gets interesting when you learn that hostcalls can call back into Wasm, so you can actually chain them alternately indefinitely: <code>Rust -&gt; Wasm -&gt; Rust -&gt; Wasm -&gt; [...]</code>.</p>
<p>We want to uphold the property that destructors run on any Rust frames that may exist when there's either a panic in a Rust hostcall, or when the Wasm guest code faults. Whether the Wasm frames get unwound or just dropped is irrelevant at this point, because as Niko mentioned there are no destructors on those frames, just enough call frame information to let the unwinder do its thing.</p>



<a name="178318996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178318996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178318996">(Oct 16 2019 at 19:03)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> I'll have to give your PR a thorough read later this afternoon, but it looks promising. the one thing I'd point out based on your comments here is that the "native" frames in the Lucet use case are generated from Wasm, not Rust. I believe Weld generates their code from LLVM, so "native" for them also means non-Rust</p>



<a name="178319683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178319683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178319683">(Oct 16 2019 at 19:12)</a>:</h4>
<p>when I wrote native I meant "generated from wasm"</p>



<a name="178326599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178326599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178326599">(Oct 16 2019 at 20:41)</a>:</h4>
<p>on a meta note, I'm going to be in "omg we have to get a demo out by <em>when</em>?" mode until mid-November. I am still able to make time for this effort, particularly if any of y'all have a specific ask, but I will not be able to check in as frequently to do proactive work on stuff. If there are pieces missing that I'd be the right contributor to provide, please let me know so I don't miss them when I'm catching up on a batch of comments</p>



<a name="178326698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178326698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178326698">(Oct 16 2019 at 20:42)</a>:</h4>
<p><span class="user-mention" data-user-id="237472">@acfoltzer</span> Is the unavailability of an MVP for cross-language unwinding blocking your November demo work?</p>



<a name="178326728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178326728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178326728">(Oct 16 2019 at 20:43)</a>:</h4>
<p>it is not; we are on nightly now and using <code>#[unwind(allowed)]</code></p>



<a name="178326901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178326901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178326901">(Oct 16 2019 at 20:45)</a>:</h4>
<p>Okay, glad there's no pressure from that direction, then!</p>



<a name="178327806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178327806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178327806">(Oct 16 2019 at 20:59)</a>:</h4>
<p>yeah, we're using <code>async</code>/<code>await</code> for the demo anyway, so it's not much extra cost at this point</p>



<a name="178328189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178328189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178328189">(Oct 16 2019 at 21:04)</a>:</h4>
<p>Well, that's at least on Beta :)</p>



<a name="178328214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/lucent%20use%20case/near/178328214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/lucent.20use.20case.html#178328214">(Oct 16 2019 at 21:05)</a>:</h4>
<p>right, now it is, at long last :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>